import json

def generate_text_from_json(json_content):
    # 将 JSON 字符串转换为 Python 字典
    data = json.loads(json_content)

    # 初始化结果文本列表
    text_parts = []

    # 处理出牌
    if 'played_cards' in data:
        cards = data['played_cards']
        if cards:
            if len(cards) == 1:
                text_parts.append(f"出牌: {cards[0]}")
            elif len(cards) == 2:
                text_parts.append(f"出牌: {cards[0]}和{cards[1]}")
            else:
                text_parts.append(f"出牌: {', '.join(cards[:-1])}和{cards[-1]}")

    # 处理其他字段
    if 'behavior' in data:
        text_parts.append(f"行为: {data['behavior']}")

    if 'play_reason' in data:
        text_parts.append(f"原因: {data['play_reason']}")

    if 'was_challenged' in data:
        was_challenged = data['was_challenged']
        # 如果是 False 或 "False"（字符串）显示 "否"，否则（包括 True 和 "True"）显示 "是"
        if was_challenged is False or (isinstance(was_challenged, str) and was_challenged.lower() == "false"):
            challenged_status = "否"
        elif was_challenged is True or (isinstance(was_challenged, str) and was_challenged.lower() == "true"):
            challenged_status = "是"
        else:
            # 其他情况（如 null、未传入、其他字符串）不显示该字段
            challenged_status = None
        if challenged_status is not None:
            text_parts.append(f"质疑: {challenged_status}")

    if 'challenge_reason' in data:
        text_parts.append(f"质疑原因: {data['challenge_reason']}")

    # 合并所有部分
    return '\n'.join(text_parts).strip()

# 测试
json_content = '''
{
    "played_cards": ["A", "A", "A"],
    "behavior": "将三张牌缓缓推至桌面中央，指尖轻点牌面，目光平静地环视一周，嘴角浮现一丝若有若无的挑衅笑意。",
    "play_reason": "当前目标牌为A，我手握三张A且无Joker，选择全部打出可确保绝对安全。三张A的压倒性数量能制造心理威慑，使下家质疑时产生顾虑。保留两张Q作为后续轮次的底牌，同时通过自信的肢体语言传递牌面真实性，降低被挑战概率。",
    "was_challenged": "False",
    "challenge_reason": "hello world!"
}
'''

text = generate_text_from_json(json_content)
print(text)